package router

import (
	"FeedXmh/app/api"
	"FeedXmh/app/dao"
	"FeedXmh/app/service/auth"
	jwt "github.com/gogf/gf-jwt"
	"github.com/gogf/gf/encoding/gparser"
	"github.com/gogf/gf/frame/g"
	"github.com/gogf/gf/net/ghttp"
	"github.com/gogf/gf/text/gstr"
)

func MiddlewareCORS(r *ghttp.Request) {
	r.Response.CORSDefault()
	r.Middleware.Next()
}
func MiddlewareLog(r *ghttp.Request) {
	url := r.URL.Path
	if url != "/Log/OperationLog" && url != "/OperationLog" {
		method := r.Method
		params := r.GetMap()
		content, _ := gparser.VarToJsonString(params)
		dao.AddOpLog("", url, method, content)
	}
	r.Middleware.Next()
}
func MiddlewareLogWithAuth(r *ghttp.Request) {
	url := r.URL.Path
	method := r.Method

	//对设置了保存日志的功能保存日志
	if dao.NeedSaveLog(url, method) {
		claims := jwt.ExtractClaims(r)
		userid := ""
		if claims != nil {
			userid = claims["userid"].(string)
		}
		content := ""
		if gstr.ToUpper(method) == "GET" {
			params := r.GetQueryMap()
			content, _ = gparser.VarToJsonString(params)
		} else if gstr.ToUpper(method) == "PUT" || gstr.ToUpper(method) == "POST" || gstr.ToUpper(method) == "DELETE" {
			params := r.GetFormMap()
			content, _ = gparser.VarToJsonString(params)
		}
		dao.AddOpLog(userid, url, method, content)
	}

	r.Middleware.Next()
}

func init() {
	s := g.Server()
	s.SetDumpRouterMap(false)

	//错误处理
	s.BindStatusHandlerByMap(map[int]ghttp.HandlerFunc{
		403: func(r *ghttp.Request) { r.Response.Writeln("403") },
		404: func(r *ghttp.Request) { r.Response.WriteTpl("/Error/404.html") },
		500: func(r *ghttp.Request) { r.Response.WriteTpl("/Error/500.html") },
	})

	//页面
	s.Group("/", func(g *ghttp.RouterGroup) {
		g.Middleware(MiddlewareCORS)
		g.GET("/", Login.Index)
		g.GET("/login", Login.Index)
		g.GET("/Login", Login.Index)
		g.GET("/Register", Login.Register)
		g.GET("/register", Login.Register)
	})
	s.Group("/Home", func(g *ghttp.RouterGroup) {
		g.Middleware(MiddlewareCORS)
		g.GET("/Index", Home.Index)
	})
	s.Group("/Dashboard", func(g *ghttp.RouterGroup) {
		g.Middleware(MiddlewareCORS)
		g.GET("/Index", Dashboard.Index)
	})
	s.Group("/Device", func(g *ghttp.RouterGroup) {
		g.Middleware(MiddlewareCORS)
		g.GET("/List", Device.List)
		g.GET("/FeedNodes", Device.FeedNodes)
		g.GET("/FeedNodesNew", Device.FeedNodesNew)
		g.GET("/Para", Device.Para)
		g.GET("/ParaReadonly", Device.ParaReadonly)
		g.GET("/ParaFgReadonly", Device.ParaFgReadonly)
		g.GET("/ParaOpHisReadonly", Device.ParaOpHisReadonly)
		g.GET("/ReplaceFeedNode", Device.ReplaceFeedNode)
		g.GET("/ReplaceGw", Device.ReplaceGw)
		g.GET("/Query", Device.Query)
		g.GET("/JyNodes", Device.JyNodes)
	})
	s.Group("/Farm", func(g *ghttp.RouterGroup) {
		g.Middleware(MiddlewareCORS)
		g.GET("/Topo", Farm.Topo)
		g.GET("/Status", Farm.Status)
		g.GET("/StatusNew", Farm.StatusNew)
	})
	s.Group("/Topo", func(g *ghttp.RouterGroup) {
		g.Middleware(MiddlewareCORS)
		g.GET("/Group", Topo.Group)
		g.GET("/Area", Topo.Area)
		g.GET("/Tree", Topo.Tree)
		g.GET("/TreeNew", Topo.TreeNew)
		g.GET("/Device", Topo.Device)
		g.GET("/Permission", Topo.Permission)
	})
	s.Group("/House", func(g *ghttp.RouterGroup) {
		g.Middleware(MiddlewareCORS)
		g.GET("/Status", House.Status)
	})

	s.Group("/RBAC", func(g *ghttp.RouterGroup) {
		g.Middleware(auth.MiddlewareCORS)
		g.GET("/User", RBAC.User)
		g.GET("/Func", RBAC.Func)
		g.GET("/Role", RBAC.Role)
		g.GET("/Action", RBAC.Action)
		g.GET("/Permission", RBAC.Permission)
		g.GET("/ApiMap", RBAC.ApiMap)
	})
	s.Group("/Admin", func(g *ghttp.RouterGroup) {
		g.Middleware(MiddlewareCORS)
		g.GET("/LoginLog", Admin.LoginLog)
		g.GET("/OpLog", Admin.OpLog)
		g.GET("/Firmware", Admin.Firmware)
		g.GET("/FirmwareUpload", Admin.FirmwareUpload)
		g.GET("/Schedule", Admin.Schedule)
		g.GET("/Dictionary", Admin.Dictionary)
	})

	s.Group("/UserProfile", func(g *ghttp.RouterGroup) {
		g.Middleware(auth.MiddlewareCORS)
		g.GET("/Profile", UserProfile.Profile)
		g.GET("/Pwd", UserProfile.Pwd)
	})

	s.Group("/Alarm", func(g *ghttp.RouterGroup) {
		g.Middleware(auth.MiddlewareCORS)
		g.GET("/Now", Alarm.Now)
		g.GET("/History", Alarm.History)
	})
	s.Group("/History", func(g *ghttp.RouterGroup) {
		g.Middleware(auth.MiddlewareCORS)
		g.GET("/FeedRecord", History.FeedRecord)
		g.GET("/FeedRecordNew", History.FeedRecordNew)
		g.GET("/FeedRecordSimple", History.FeedRecordSimple)
		g.GET("/FeedBnRecordSimple", History.FeedBnRecordSimple)
		g.GET("/FeedJyRecordSimple", History.FeedJyRecordSimple)
		g.GET("/FeedHisDay", History.FeedHisDay)

		g.GET("/OpLogSetPara", History.OpLogSetPara)
		g.GET("/OpLogSetDay", History.OpLogSetDay)
		g.GET("/OpLogSetCalc", History.OpLogSetCalc)
		g.GET("/DeliverLog", History.DeliverLog)
	})

	s.Group("/Feed", func(g *ghttp.RouterGroup) {
		g.Middleware(auth.MiddlewareCORS)
		g.GET("/FeedPlan", Feed.FeedPlan)
		g.GET("/FeedPlanNew", Feed.FeedPlanNew)
		g.GET("/FeedPlanParaReadonly", Feed.FeedPlanParaReadonly)
		g.GET("/FeedPlanParaEdit", Feed.FeedPlanParaEdit)
		g.GET("/FgPlanParaEdit", Feed.FgPlanParaEdit)
		g.GET("/FgPlanParaReadonly", Feed.FgPlanParaReadonly)
	})

	s.Group("/Ext", func(g *ghttp.RouterGroup) {
		g.Middleware(auth.MiddlewareCORS)
		g.GET("/Weather", Ext.Weather)
	})

	//----------------------------------以下API-------------------------------------------

	s.Group("/wechat/", func(g *ghttp.RouterGroup) {
		g.Middleware(MiddlewareCORS)
		g.ALL("/index", api.WechatAPI.Index)
		g.PUT("/user/sync", api.WechatAPI.SyncAccount)

		g.PUT("/notice/testHappen", api.WechatAPI.TestHappen)
		g.PUT("/notice/testCancel", api.WechatAPI.TestCancel)
	})

	s.Group("/Api/", func(g *ghttp.RouterGroup) {
		g.POST("/Login", auth.GfJWTMiddleware.LoginHandler)
	})
	s.Group("/Api/", func(g *ghttp.RouterGroup) {
		g.Middleware(auth.MiddlewareCORS, auth.MiddlewareAuth, MiddlewareLogWithAuth)
		g.POST("/Logout", auth.GfJWTMiddleware.LogoutHandler)
	})
	s.Group("/Api/", func(g *ghttp.RouterGroup) {
		g.Middleware(auth.MiddlewareCORS, auth.MiddlewareAuth, MiddlewareLogWithAuth)
		g.POST("/RefreshToken", auth.GfJWTMiddleware.RefreshHandler)
	})

	s.Group("/Api/Public", func(g *ghttp.RouterGroup) {
		g.Middleware(auth.MiddlewareCORS)
		g.GET("/AppInfo", api.Public.AppInfo)
	})

	s.Group("/Api/Topo", func(g *ghttp.RouterGroup) {
		g.Middleware(auth.MiddlewareCORS, auth.MiddlewareAuth, MiddlewareLogWithAuth)
		g.GET("/", api.Topo.GET)
		//g.GET("/GetTree", api.Topo.GetTree)
		g.GET("/GetAsync", api.Topo.GetNodesAsync)
		g.GET("/Export", api.Topo.ExportNodes)
	})

	s.Group("/Api/Org", func(g *ghttp.RouterGroup) {
		g.Middleware(auth.MiddlewareCORS, auth.MiddlewareAuth, MiddlewareLogWithAuth)
		g.GET("/", api.Org.GET)
		g.PUT("/", api.Org.PUT)
		g.POST("/", api.Org.POST)
		g.DELETE("/", api.Org.DELETE)
	})

	//API
	s.Group("/Api/Device", func(g *ghttp.RouterGroup) {

		g.Middleware(auth.MiddlewareCORS, auth.MiddlewareAuth, MiddlewareLogWithAuth)
		//g.Middleware(auth.MiddlewareCORS)
		g.GET("/", api.Device.Get)
		g.GET("/Page", api.Device.GetPage)
		g.POST("/", api.Device.Post)
		g.PUT("/", api.Device.Put)
		g.DELETE("/", api.Device.Delete)
		g.PUT("/Allocate", api.Device.Allocate)
		g.GET("/ByHouse", api.Device.GetByHouse)
		g.GET("/ForAllocate", api.Device.GetForAllocate)

		g.GET("/Query", api.Device.Query)

		g.GET("/Feednode/Page", api.Feednode.GetPage)
		g.GET("/Feednode", api.Feednode.Get)
		g.GET("/Feednode/List", api.Feednode.GetList)
		g.GET("/Feednode/CitySort", api.Feednode.GetCitySort)
		g.GET("/Feednode/ProvinceSort", api.Feednode.GetProvinceSort)
		g.GET("/Feednode/Simple", api.Feednode.GetSimple)

		g.PUT("/Feednode/Earmark", api.Feednode.SetEarmark)
		g.PUT("/Feednode/PigType", api.Feednode.SetPigType)

		g.GET("/FeednodeReplace/Page", api.Feednode_replace.GetPage)
		g.POST("/FeednodeReplace", api.Feednode_replace.Post)
		g.DELETE("/FeednodeReplace", api.Feednode_replace.DELETE)

		//g.GET("/Jy", api.Jy.Get)

		g.GET("/HzfgwReplace/Page", api.Hzfgw_replace.GetPage)
		g.POST("/HzfgwReplace", api.Hzfgw_replace.Post)

		g.PUT("/Gw/SetNodeSn", api.Gw.SetNodeSn)
		g.PUT("/Gw/SetNodeDay", api.Gw.SetNodeDay)
		g.PUT("/Gw/SetNodeHnum", api.Gw.SetNodeHnum)
		g.PUT("/Gw/SetNodeMode", api.Gw.SetNodeMode)
		g.PUT("/Gw/SetNodeCalcFeed", api.Gw.SetNodeCalcFeed)
		g.PUT("/Gw/SetNodeCalcWater", api.Gw.SetNodeCalcWater)
		g.PUT("/Gw/SetNodeFeedOffset", api.Gw.SetNodeFeedOffset)
		g.PUT("/Gw/SetNodeWaterPTTO", api.Gw.SetNodeWaterPTTO)
		g.PUT("/Gw/SetNodeWaterFeed", api.Gw.SetNodeWaterFeed)
		g.PUT("/Gw/SetNodeAD", api.Gw.SetNodeAD)
		g.PUT("/Gw/SetNodeWpAddr", api.Gw.SetNodeWpAddr)
		g.PUT("/Gw/SetNodePassword", api.Gw.SetNodePassword)

		g.GET("/Gw/Status", api.Gw.GetStatus)
		g.GET("/Gw/UpdateStatus", api.Gw.UpdateStatus)
		g.GET("/Gw/Clock", api.Gw.GetClock)
		g.PUT("/Gw/ClearRecord", api.Gw.ClearRecord)
		g.PUT("/Gw/ManualFeed", api.Gw.ManualFeed)
		g.PUT("/Gw/ManualDeliverFeed", api.Gw.ManualDeliverFeed)
		g.PUT("/Gw/ManualDeliverFeedBySn", api.Gw.ManualDeliverFeedBySn)
		g.PUT("/Gw/Qrcode", api.Gw.Qrcode)
		g.PUT("/Gw/Clock", api.Gw.SetClock)
		g.GET("/Gw/Param", api.Gw.GetParam)
		g.GET("/Gw/ExParam", api.Gw.GetExParam)
		g.PUT("/Gw/Param", api.Gw.SetParam)
		g.PUT("/Gw/ExParam", api.Gw.SetExParam)
		g.PUT("/Gw/ExParamName", api.Gw.SetExParamName)
		g.PUT("/Gw/ExParamLimit", api.Gw.SetExParamLimit)
		g.PUT("/Gw/NodeParam", api.Gw.SetNodeParam)
		//g.PUT("/Gw/NodeBnParam", api.Gw.SetNodeBnParam)
		//g.PUT("/Gw/NodeJyParam", api.Gw.SetNodeJyParam)
		g.PUT("/Gw/NodeFgParam", api.Gw.SetNodeFgParam)
		g.PUT("/Gw/ResetNodeParam", api.Gw.ResetNodeParam)
		g.PUT("/Gw/UpdateNode", api.Gw.UpdateNode)
		g.PUT("/Gw/Update", api.Gw.Update)
		g.GET("/Gw/Online", api.Gw.GetOnline)
		//g.GET("/Gw/Record", api.Gw.GetRecord)
	})

	s.Group("/Api/Pig", func(g *ghttp.RouterGroup) {
		g.Middleware(auth.MiddlewareCORS, auth.MiddlewareAuth, MiddlewareLogWithAuth)
		//g.Middleware(auth.MiddlewareCORS)
		g.GET("/", api.Pig.Get)
		g.POST("/", api.Pig.Post)
		g.PUT("/", api.Pig.Put)
		g.DELETE("/", api.Pig.Delete)
		g.PUT("/PigNum", api.Pig.SetPigNum)
	})

	s.Group("/Api/Alarm", func(g *ghttp.RouterGroup) {
		g.Middleware(auth.MiddlewareCORS, auth.MiddlewareAuth, MiddlewareLogWithAuth)
		//g.Middleware(auth.MiddlewareCORS)
		//g.GET("/", api.Alarm.Get)
		g.DELETE("/", api.Alarm.Delete)
		g.GET("/Page", api.Alarm.GetAlarmHisPage)
		g.GET("/NowPage", api.Alarm.GetAlarmNowPage)
		g.GET("/Happen", api.Alarm.GetCurAlarm)
		g.GET("/Happen/Num", api.Alarm.GetCurAlarmNum)
		g.GET("/FarmSummary", api.Alarm.FarmSummary)
	})

	s.Group("/Api/History", func(g *ghttp.RouterGroup) {
		g.Middleware(auth.MiddlewareCORS, auth.MiddlewareAuth, MiddlewareLogWithAuth)
		g.GET("/FeedRecord/Page", api.Feed_record.GetPage)
		g.GET("/FeedRecord", api.Feed_record.Get)
		g.GET("/FeedRecord/Export", api.Feed_record.Export)
		g.GET("/FeedRecord/ExportSimple", api.Feed_record.ExportSimple)
		g.GET("/StatusHis", api.Status_his.Get)
		g.GET("/FeedHis/Page", api.Feed_his.GetPage)
		g.GET("/FeedHis", api.Feed_his.Get)
		g.GET("/FeedHis/Export", api.Feed_his.Export)
		g.GET("/FeedHis/ExportHourFeed", api.Feed_his.ExportHourFeed)

		//g.GET("/FeedBnRecord/Page", api.Feed_bn_record.GetPage)
		//g.GET("/FeedBnRecord/ExportSimple", api.Feed_bn_record.ExportSimple)
	})
	s.Group("/Api/DeviceDefine", func(g *ghttp.RouterGroup) {
		g.Middleware(auth.MiddlewareCORS, auth.MiddlewareAuth, MiddlewareLogWithAuth)
		g.GET("/", api.Device_define.Get)
	})

	s.Group("/Api/Firmware", func(g *ghttp.RouterGroup) {
		g.Middleware(auth.MiddlewareCORS, auth.MiddlewareAuth, MiddlewareLogWithAuth)
		g.GET("/", api.Firmware.Get)
		g.DELETE("/", api.Firmware.Delete)
		g.POST("/Upload", api.Firmware.Upload)
		g.PUT("/Default", api.Firmware.Default)
		g.PUT("/", api.Firmware.PUT)
	})
	s.Group("/Api", func(g *ghttp.RouterGroup) {
		g.Middleware(auth.MiddlewareCORS, auth.MiddlewareAuth, MiddlewareLogWithAuth)
		g.GET("/Menu", api.Menu.Get)
		//g.GET("/User", api.User.GET)
	})
	s.Group("/Api/Group", func(g *ghttp.RouterGroup) {
		g.Middleware(auth.MiddlewareCORS, auth.MiddlewareAuth, MiddlewareLogWithAuth)
		g.GET("/", api.Group.GET)
		g.PUT("/", api.Group.PUT)
		g.POST("/", api.Group.POST)
		g.DELETE("/", api.Group.DELETE)
	})
	s.Group("/Api/Area", func(g *ghttp.RouterGroup) {
		g.Middleware(auth.MiddlewareCORS, auth.MiddlewareAuth, MiddlewareLogWithAuth)
		g.GET("/", api.Area.GET)
		g.PUT("/", api.Area.PUT)
		g.POST("/", api.Area.POST)
		g.DELETE("/", api.Area.DELETE)
	})

	s.Group("/Api/Farm", func(g *ghttp.RouterGroup) {
		g.Middleware(auth.MiddlewareCORS, auth.MiddlewareAuth, MiddlewareLogWithAuth)
		g.GET("/", api.Farm.GET)
		g.GET("/Users", api.Farm.GetUsers)
		g.PUT("/Users", api.Farm.SetUsers)
		g.PUT("/", api.Farm.PUT)
		g.POST("/", api.Farm.POST)
		g.DELETE("/", api.Farm.DELETE)
		g.GET("/Topo", api.Farm.Topo)
		g.GET("/List", api.Farm.List)
		g.GET("/SummaryList", api.Farm.ListWithSummaryInfo)
		g.GET("/List/ByUser", api.Farm.ListByUser)
		//g.GET("/DeviceData", api.Farm.DeviceData)
		g.GET("/TodayFeed", api.Farm.TodayFeed)
		g.GET("/MonthFeed", api.Farm.MonthFeed)
		g.GET("/SumFeed", api.Farm.SumFeed)
		g.GET("/DaySumFeed", api.Farm.DaySumFeed)
		g.GET("/DaySumFeed/Export", api.Farm.ExportDaySumFeed)
		g.GET("/DayAvgFeed/Export", api.Farm.ExportDayAvgFeed)

		g.GET("/SumMode", api.Farm.SumMode)
		g.GET("/MapData", api.Farm.MapData)

		g.GET("/SummaryInfo", api.Farm.SummaryInfo)
		g.GET("/FeedHighLow", api.Farm.FeedHighLow)
		g.GET("/HouseSummarySort", api.Farm.HouseSummarySort)
		g.GET("/HouseSummarySort/Export", api.Farm.ExportHouseSummarySort)
	})

	s.Group("/Api/FeedPlan", func(g *ghttp.RouterGroup) {
		g.Middleware(auth.MiddlewareCORS, auth.MiddlewareAuth, MiddlewareLogWithAuth)
		g.GET("/", api.Feed_plan.GET)
		g.GET("/Page", api.Feed_plan.GetPage)
		g.PUT("/", api.Feed_plan.PUT)
		g.POST("/", api.Feed_plan.POST)
		g.DELETE("/", api.Feed_plan.DELETE)
		g.PUT("/Allocate", api.Feed_plan.Allocate)
	})

	s.Group("/Api/FeedPlanNew", func(g *ghttp.RouterGroup) {
		g.Middleware(auth.MiddlewareCORS, auth.MiddlewareAuth, MiddlewareLogWithAuth)
		g.GET("/", api.Feed_plan_new.GET)
		g.GET("/Page", api.Feed_plan_new.GetPage)
		g.PUT("/", api.Feed_plan_new.PUT)
		g.POST("/", api.Feed_plan_new.POST)
		g.DELETE("/", api.Feed_plan_new.DELETE)
		g.PUT("/Allocate", api.Feed_plan_new.Allocate)
	})

	s.Group("/Api/House", func(g *ghttp.RouterGroup) {
		g.Middleware(auth.MiddlewareCORS, auth.MiddlewareAuth, MiddlewareLogWithAuth)
		g.GET("/", api.House.GET)
		g.GET("/Users", api.House.GetUsers)
		g.PUT("/Users", api.House.SetUsers)
		g.GET("/Detail", api.House.GetWithDetail)
		g.GET("/SummaryInfo", api.House.SummaryInfo)
		g.PUT("/", api.House.PUT)
		g.POST("/", api.House.POST)
		g.DELETE("/", api.House.DELETE)
		g.GET("/List/ByUser", api.House.ListByUser)

		g.GET("/DeviceData", api.House.DeviceData)
		g.GET("/TodayFeed", api.House.TodayFeed)
		g.GET("/DaySumFeed", api.House.DayFeed)
		g.GET("/DayAvgFeed", api.House.DayFeed)
		g.GET("/DayAvgFeed/Export", api.House.ExportDayFeed)
	})
	s.Group("/Api/Room", func(g *ghttp.RouterGroup) {
		g.Middleware(auth.MiddlewareCORS, auth.MiddlewareAuth, MiddlewareLogWithAuth)
		g.GET("/", api.Room.GET)
		g.PUT("/", api.Room.PUT)
		g.POST("/", api.Room.POST)
		g.DELETE("/", api.Room.DELETE)
	})

	//API
	s.Group("/Api/User", func(g *ghttp.RouterGroup) {
		g.Middleware(auth.MiddlewareCORS, auth.MiddlewareAuth, MiddlewareLogWithAuth)
		g.GET("/", api.User.GET)
		g.GET("/Info", api.User.Info)
		g.POST("/", api.User.POST)
		g.PUT("/", api.User.PUT)
		g.DELETE("/", api.User.DELETE)
		g.GET("/List", api.User.GetUsers)
		g.GET("/Actions", api.User.GetUserActions)
		g.GET("/Farms", api.User.GetUserFarms)
		g.PUT("/Org", api.User.SetUserOrg)
		g.GET("/Devices", api.User.GetUserDevices)
		g.GET("/Permission", api.User.GetUserPermission)
		g.PUT("/Enable", api.User.Enable)
		g.PUT("/Disable", api.User.Disable)
		g.PUT("/SetAdmin", api.User.SetAdmin)
		g.PUT("/ResetPwd", api.User.ResetPwd)
		g.PUT("/Profile", api.User.EditProfile) //用户修改资料
		g.PUT("/Pwd", api.User.ChangePwd)       //用户修改密码
	})

	s.Group("/Api/Role", func(g *ghttp.RouterGroup) {
		g.Middleware(auth.MiddlewareCORS, auth.MiddlewareAuth, MiddlewareLogWithAuth)
		g.GET("/", api.Role.GET)
		g.POST("/", api.Role.POST)
		g.PUT("/", api.Role.PUT)
		g.DELETE("/", api.Role.DELETE)
		g.GET("/List", api.Role.GET)
	})

	s.Group("/Api/Action", func(g *ghttp.RouterGroup) {
		g.Middleware(auth.MiddlewareCORS, auth.MiddlewareAuth, MiddlewareLogWithAuth)
		g.GET("/", api.Action.GET)
		g.POST("/", api.Action.POST)
		g.PUT("/", api.Action.PUT)
		g.DELETE("/", api.Action.DELETE)
	})

	s.Group("/Api/Func", func(g *ghttp.RouterGroup) {
		g.Middleware(auth.MiddlewareCORS, auth.MiddlewareAuth, MiddlewareLogWithAuth)
		g.GET("/", api.Func.GET)
		g.POST("/", api.Func.POST)
		g.PUT("/", api.Func.PUT)
		g.DELETE("/", api.Func.DELETE)
	})
	s.Group("/Api/Permission", func(g *ghttp.RouterGroup) {
		g.Middleware(auth.MiddlewareCORS, auth.MiddlewareAuth, MiddlewareLogWithAuth)
		g.GET("/", api.Permission.GET)
		g.POST("/", api.Permission.POST)
		g.PUT("/", api.Permission.PUT)
		g.DELETE("/", api.Permission.DELETE)
	})
	s.Group("/Api/ApiMap", func(g *ghttp.RouterGroup) {
		g.Middleware(auth.MiddlewareCORS, auth.MiddlewareAuth, MiddlewareLogWithAuth)
		g.GET("/", api.Api_map.GET)
		g.POST("/", api.Api_map.POST)
		g.PUT("/", api.Api_map.PUT)
		g.DELETE("/", api.Api_map.DELETE)
	})

	s.Group("/Api/Dictionary", func(g *ghttp.RouterGroup) {
		g.Middleware(auth.MiddlewareCORS, auth.MiddlewareAuth, MiddlewareLogWithAuth)
		g.GET("/", api.Dictionary.GET)
		g.POST("/", api.Dictionary.POST)
		g.PUT("/", api.Dictionary.PUT)
		g.DELETE("/", api.Dictionary.DELETE)
	})

	//API
	s.Group("/Api/Utils", func(g *ghttp.RouterGroup) {
		g.Middleware(auth.MiddlewareCORS, auth.MiddlewareAuth, MiddlewareLogWithAuth)
		g.GET("/Hnum", api.Utils.GetHmum)
	})

	s.Group("/Api/Log", func(g *ghttp.RouterGroup) {
		g.Middleware(auth.MiddlewareCORS, auth.MiddlewareAuth, MiddlewareLogWithAuth)
		g.GET("/LoginLog", api.Login_log.GET)
		g.GET("/OpLog", api.Op_log.GET)
		g.GET("/OpLogPara", api.Op_log_set_para.GET)
		g.GET("/OpLogCalc", api.Op_log_set_calc.GET)
		g.GET("/OpLogDay", api.Op_log_set_day.GET)
		//g.GET("/DeliverLog", api.Deliver_log.GET)
	})

	s.Group("/Api/MiniProgram", func(g *ghttp.RouterGroup) {
		g.Middleware(auth.MiddlewareCORS)
		g.GET("/Jscode2session", api.Mini_program.Jscode2session)
		g.GET("/CityLookup", api.Mini_program.CityLookup)
		g.GET("/WeatherNow", api.Mini_program.WeatherNow)
		g.GET("/Weather24h", api.Mini_program.Weather24h)
		g.GET("/Weather7d", api.Mini_program.Weather7d)

		g.GET("/GetUser", api.Mini_program.GetUser)
		g.POST("/Login", api.Mini_program.Login)
		g.POST("/ChangePwd", api.Mini_program.ChangePwd)
		g.POST("/Logout", api.Mini_program.Logout)

		g.GET("/FarmList", api.Mini_program.FarmList)
		g.GET("/HouseList", api.Mini_program.HouseList)
		g.GET("/FeedNodeSimple", api.Mini_program.FeedNodeSimple)
		g.GET("/FeedNode", api.Mini_program.FeedNode)
		g.GET("/Farm/SumMode", api.Mini_program.FarmSumMode)

		g.GET("/Farm/SumFeed", api.Mini_program.FarmSumFeed)
		g.GET("/Farm/DaySumFeed", api.Mini_program.FarmDaySumFeed)
		g.GET("/Farm/DayAvgFeed", api.Mini_program.FarmDayAvgFeed)

		g.GET("/House/DaySumFeed", api.Mini_program.HouseDaySumFeed)
		g.GET("/House/DayAvgFeed", api.Mini_program.HouseDayAvgFeed)

		g.GET("/GetHouseWithDetail", api.Mini_program.GetHouseWithDetail)

		g.PUT("/SetDefaultFarm", api.Mini_program.SetDefaultFarm)

	})
}
